#include "Socket.hpp"
#include "TcpServer.hpp"
#include <iostream>
#include <unordered_map>

using namespace SocketModule;

const std::string gspace = " ";
const std::string glinespace = "\r\n";

class HttpRequest
{
public:
    HttpRequest()
    {

    }

    std::string Serialize()
    {
        return std::string();
    }

    bool DeSerialize(std::string &reqstr)
    {
        return true;
    }

    ~HttpRequest()
    {

    }
private:
    std::string _method;
    std::string _url;
    std::string _version;

    std::unordered_map<std::string, std::string> _header;
    std::string _blankline;
    std::string _text;
};

class Http
{
public:
    Http(uint16_t port):tsvrp(std::make_unique<TcpServer>(port))
    {

    }

    void HandlerHttpRequest(std::shared_ptr<Socket> &sock, InetAddr &client)
    {
#ifndef DEBUG
#define DEBUG
        std::string httpreqstr;
        sock->Recv(&httpreqstr);
        std::cout << httpreqstr;
#endif
    }

    void Start()
    {
        tsvrp->Start([this](std::shared_ptr<Socket> &sock, InetAddr &client)
        {
            this->HandlerHttpRequest(sock, client);
        });
    }

    ~Http()
    {

    }
private:
    std::unique_ptr<TcpServer> tsvrp;
};